space of pos def 3x3 correlation matrices

Author

Ben Bolker

Published

November 5, 2024

library(rgl)
library(misc3d)
rgl::setupKnitr(autoprint = TRUE)
options(rgl.useNULL=TRUE)

Consider this \(3\times 3\) correlation matrix: \[ C = \left( \begin{array}{ccc} 1 & \rho_1 & \rho_2 \\ \rho_1 & 1 & \rho_3 \\ \rho_2 & \rho_3 & 1 \end{array} \right) \]

What does the set \(\{\rho_1, \rho_2, \rho_3\}: C \textrm{ is pos. def.}\) look like?

Brute force: generate

n <- 51
cvec <- seq(-1, 1, length.out = n)
M <- as.matrix(expand.grid(r1=cvec, r2=cvec, r3=cvec))
efun <- function(x) {
    M <- diag(3)
    ## works for 3x3 but not more generally?
    M[lower.tri(M)] <- x
    M[upper.tri(M)] <- x
    M
}
efun2 <- function(x) min(eigen(efun(x), only.values = TRUE)$values)
system.time(e.val <- apply(M, 1, efun2))
   user  system elapsed 
 20.339   5.601  26.216 
aa <- array(e.val, c(n, n, n))
## open3d()
misc3d::contour3d(aa, cvec, cvec, cvec, level = 0, color="blue", alpha = 0.5)
axes3d()
grid3d(side = c("x-", "y-", "z-"))

Or with sympy:

from sympy import *
var('rho1 rho2 rho3');
M = Matrix([[1, rho1, rho2], [rho1, 1, rho3], [rho2, rho3, 1]])
ee = M.eigenvals()
show = lambda x: print('$$\n%s\n$$\n' % latex(x))
show(ee)

\[ \left\{ - \frac{\left(- \frac{1}{2} - \frac{\sqrt{3} i}{2}\right) \sqrt[3]{- 27 \rho_{1} \rho_{2} \rho_{3} + \frac{\sqrt{2916 \rho_{1}^{2} \rho_{2}^{2} \rho_{3}^{2} - 4 \left(3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}\right)^{3}}}{2}}}{3} + 1 - \frac{3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}}{3 \left(- \frac{1}{2} - \frac{\sqrt{3} i}{2}\right) \sqrt[3]{- 27 \rho_{1} \rho_{2} \rho_{3} + \frac{\sqrt{2916 \rho_{1}^{2} \rho_{2}^{2} \rho_{3}^{2} - 4 \left(3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}\right)^{3}}}{2}}} : 1, \ - \frac{\left(- \frac{1}{2} + \frac{\sqrt{3} i}{2}\right) \sqrt[3]{- 27 \rho_{1} \rho_{2} \rho_{3} + \frac{\sqrt{2916 \rho_{1}^{2} \rho_{2}^{2} \rho_{3}^{2} - 4 \left(3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}\right)^{3}}}{2}}}{3} + 1 - \frac{3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}}{3 \left(- \frac{1}{2} + \frac{\sqrt{3} i}{2}\right) \sqrt[3]{- 27 \rho_{1} \rho_{2} \rho_{3} + \frac{\sqrt{2916 \rho_{1}^{2} \rho_{2}^{2} \rho_{3}^{2} - 4 \left(3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}\right)^{3}}}{2}}} : 1, \ - \frac{\sqrt[3]{- 27 \rho_{1} \rho_{2} \rho_{3} + \frac{\sqrt{2916 \rho_{1}^{2} \rho_{2}^{2} \rho_{3}^{2} - 4 \left(3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}\right)^{3}}}{2}}}{3} + 1 - \frac{3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}}{3 \sqrt[3]{- 27 \rho_{1} \rho_{2} \rho_{3} + \frac{\sqrt{2916 \rho_{1}^{2} \rho_{2}^{2} \rho_{3}^{2} - 4 \left(3 \rho_{1}^{2} + 3 \rho_{2}^{2} + 3 \rho_{3}^{2}\right)^{3}}}{2}}} : 1\right\} \]

It would be interesting to simulate a bunch of multivariate data sets with large noise/low replication and look at the distribution of \(\{\rho_1, \rho_2, \rho_3\}\) estimates in this space (i.e., how do they cluster on the boundaries?)